package com.example.scugroup8.controller;

import com.example.scugroup8.pojo.UserLines;
import com.example.scugroup8.service.impl.UserLinesServiceImpl;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * (UserLines)表控制层
 *
 * @author zhoumou
 * @version 1.0
 * @since 2022-06-20 21:36:53
 */
@RestController
@RequestMapping("/userLines")
@Api(value = "(UserLines)管理", tags = "(UserLines)管理接口API")
@ApiResponses({
        @ApiResponse(code = 400, message = "请求参数不完整或者错误"),
        @ApiResponse(code = 404, message = "找不到页面"),
        @ApiResponse(code = 405, message = "请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code = 406, message = "页面地址和接口名冲突"),
        @ApiResponse(code = 415, message = "请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code = 500, message = "后台服务逻辑错误")
})
public class UserLinesController {
    /**
     * 服务对象
     */
    @Resource
    private UserLinesServiceImpl userLinesServiceImpl;

    /**
     * 通过主键查询单条数据
     *
     * @param page 需要查询的页码
     * @param name 模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口", notes = "列表查询分页接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "name", value = "**名称", paramType = "query", dataType = "String", required = false)
    })
    public Map<String, Object> selectByPage(@RequestParam(name = "page") int page, String name) {
        return this.userLinesServiceImpl.selectByPage(page, name);
    }

    /**
     * 查询所有数据
     *
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有数据接口", notes = "查询所有数据接口", httpMethod = "GET")
    public Map<String, Object> selectAll() {
        return this.userLinesServiceImpl.selectAll();
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/shanChuById", method = RequestMethod.POST)
    @ApiOperation(value = "根据一个主键删除一条**记录的接口",notes = "根据一个主键删除一条**记录的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.userLinesServiceImpl.deleteById(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/chaXunById", method = RequestMethod.GET)
    @ApiOperation(value = "通过主键查询一个**的接口", notes = "通过主键查询一个**的接口", httpMethod = "GET")
    public Map<String, Object> selectById(Integer id) {
        return this.userLinesServiceImpl.selectById(id);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param userLines 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个**的接口", notes = "通过主键更新一个**的接口", httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "userLines", value = "pojo模型", required = true) UserLines userLines) {
        return this.userLinesServiceImpl.updateById(userLines);
    }

    /**
     * 客户端新增数据，绑定用户名和主板id
     *
     * @param userLines 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "注册", notes = "根据完整记录新增一个绑定用户和主板id的接口", httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody @ApiParam(name = "userLines", value = "pojo模型", required = true) UserLines userLines) {
        return this.userLinesServiceImpl.insert(userLines);
    }

//    /**
//     * 客户端通过basename进行扫描，判断主机是否已经注册
//     *
//     * @param basename 对应的主板id
//     * @return 存在主机返回true，否则返回false
//     */
//    @RequestMapping(value = "/getUserLinesByBasename", method = RequestMethod.GET)
//    @ApiOperation(value = "查询", notes = "根据完整记录新增一个通过主机名查询的接口", httpMethod = "GET")
//    public Map<String, Object> getUserLinesByBasename(@RequestParam("basename") String basename) {
//        return this.userLinesServiceImpl.getUserLinesByBasename(basename);
//    }
}